package com.tobestronger.shouxiespringframework.beans.factory.config;

import com.tobestronger.shouxiespringframework.beans.PropertyValues;

/**
 * 定义 Bean 实例信息
 */
public class BeanDefinition {

    String SCOPE_SINGLETON = ConfigurableBeanFactory.SCOPE_SINGLETON;

    String SCOPE_PROTOTYPE = ConfigurableBeanFactory.SCOPE_PROTOTYPE;


    private Class beanClass;

    /**
     * 属性信息集
     */
    private PropertyValues propertyValues;

    /**
     * bean初始化时回调方法
     */
    private String initMethodName;

    /**
     * bean销毁时回调方法
     */
    private String destroyMethodName;

    /**
     * 作用域
     */
    private String scope = SCOPE_SINGLETON;

    private boolean singleton = true;

    private boolean prototype = false;

    public BeanDefinition(Class beanClass) {
        this(beanClass,null);
    }

    public BeanDefinition(Class beanClass, PropertyValues propertyValues) {
        this.beanClass = beanClass;
        this.propertyValues = ( (propertyValues != null) ? propertyValues : new PropertyValues() );
    }

    public Class getBeanClass() {
        return beanClass;
    }

    public void setBeanClass(Class beanClass) {
        this.beanClass = beanClass;
    }

    public PropertyValues getPropertyValues() {
        return propertyValues;
    }

    public void setPropertyValues(PropertyValues propertyValues) {
        this.propertyValues = propertyValues;
    }

    public String getInitMethodName() {
        return initMethodName;
    }

    public void setInitMethodName(String initMethodName) {
        this.initMethodName = initMethodName;
    }

    public String getDestroyMethodName() {
        return destroyMethodName;
    }

    public void setDestroyMethodName(String destroyMethodName) {
        this.destroyMethodName = destroyMethodName;
    }

    public void setScope(String scope) {
        this.scope = scope.toLowerCase();
        this.singleton = SCOPE_SINGLETON.equals(this.scope);
        this.prototype = SCOPE_PROTOTYPE.equals(this.scope);
    }

    public boolean isSingleton() {
        return singleton;
    }

    public boolean isPrototype() {
        return prototype;
    }


}
